/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CapaLogica;

import CapaAccesoBD.Conector;
import java.util.ArrayList;

/**
 *
 * @author Amejia
 */
public class MultiRegistro {
    
 
        public ArrayList<Registro> buscarRegistrosPorCongregacion(String pidCongregacion,String pperiodo) throws Exception{
            Registro objRegistro;
            ArrayList<Registro> listaRegistros;
            String sql;
            java.sql.ResultSet rs;
				sql = "SELECT * FROM TRegistro"+
                  " WHERE idCongregacion ='"+pidCongregacion+"'";
                  
                  if(pperiodo.length()>0){
                    sql+=" and periodo='"+pperiodo+"'";  
                  }
                  sql+=";";
                                
            try{
                rs = Conector.getConector().ejecutarSQL(sql,true);
                listaRegistros = new ArrayList();
                if (rs.next()) {
                    do{
                        objRegistro = new Registro(rs.getString("id"), rs.getString("fecha"), rs.getDouble("monto"), rs.getString("periodo"), rs.getString("idCongregacion"));
                        listaRegistros.add(objRegistro);
                    }while (rs.next());
                }
            }catch (Exception e){
                throw new Exception (e.getMessage());
            }
            rs.close();
            
            return listaRegistros;
        }
        
      public ArrayList<Registro> buscarRegistrosPorDistrito(String pidDistrito) throws Exception{
            Registro objRegistro;
            ArrayList<Registro> listaRegistros;
            String sql;
            java.sql.ResultSet rs;
				sql = "SELECT a* FROM TRegistro a, TCongregacion b"+
                  " WHERE a.idCongregacion =b.Id AND b.id_distrito='"+pidDistrito+"';";
            try{
                rs = Conector.getConector().ejecutarSQL(sql,true);
                listaRegistros = new ArrayList();
                if (rs.next()) {
                    do{
                        objRegistro = new Registro(rs.getString("id"), rs.getString("fecha"), rs.getDouble("monto"), rs.getString("periodo"), rs.getString("idCongregacion"));
                        listaRegistros.add(objRegistro);
                    }while (rs.next());
                }
            }catch (Exception e){
                throw new Exception (e.getMessage());
            }
            rs.close();
            
            return listaRegistros;
        }
        

}
